<?php 
class page_admin extends MX_Controller{
	public function index(){
		$limit=25;
		$filter=array('category'=>0,'date'=>'');
		$paging=array('page_current'=>0,'number_affiche'=>$limit);
		$adminMenu= $this->load->module('adminMenu/index');
		$sort=array('title'=>'desc','page_counter'=>'desc');
		if(isset($_POST['sort']))
			foreach ($sort as $key=>$val)
				$sort[$key]=$this->input->post($key);

		$setting =$this->load->Module('setting/admin');
		$this->template=$this->config->config['admin_template'];
		
		//prendre tous les id des produits
		$listAllShop=$this->model()->get_list_page($filter,$sort,$paging);
		$option_filter_date=$this->model()->get_month_year_create();
		$data=array(
				'update_footer'=>'StarView 2013',
				'admin_title'=>'Control Admin Page',
				'sort'=>$sort,
				'filter'=>$filter,
				'option_filter_date'=>$option_filter_date,
				'admin_menu'=>$adminMenu->generateAdminMenu(),
				'listAllProducts'=>$listAllShop,
				'totalActive'=>$this->model()->get_total_page(true),
				'total'=>$this->model()->get_total_page()
		);
		
		
		$this->view(
				array('admin-header',
						'page',
						'admin-footer'),
				$data); // Display the page
	}
	public function new_page(){
		$adminMenu= $this->load->module('adminMenu/index');
		$setting =$this->load->Module('setting/admin');
		$this->template=$this->config->config['admin_template'];
		
		$data=array(
				'update_footer'=>'StarView 2013',
				'admin_title'=>'Control Admin',
				'admin_menu'=>$adminMenu->generateAdminMenu()
		);
	
		$this->view(
				array('admin-header',
						'page-new',
						'admin-footer'),
					$data); // Display the page
		}
		public function edit($id){
			$adminMenu= $this->load->module('adminMenu/index');
			$setting =$this->load->Module('setting/admin');
			$this->template=$this->config->config['admin_template'];
			$page=$this->model()->get_infoPage($id);
			$data=array(
					'update_footer'=>'StarView 2013',
					'admin_title'=>'Control Admin Page Modifier',
					'page'=>$page,
					'admin_menu'=>$adminMenu->generateAdminMenu()
			);
		
			$this->view(
					array(  'admin-header',
							'page-edit',
							'admin-footer'),
							$data); // Display the page
		}
		public function page_edit(){

			$this->load->helper('url');
			$page=new stdclass;
			$page->id= $this->input->post('id');
			$page->name= $this->input->post('name');
			$page->title= $this->input->post('title');
			
			$page->heading= $this->input->post('heading');
			$page->content= $this->input->post('content');
			$page->metakeywords= $this->input->post('metakeywords');
			$page->metadescription= $this->input->post('metadescription');
			if($page->metadescription==''){
				$page->metadescription=preg_replace('/\s+?(\S+)?$/', '', substr(strip_tags($page->content), 0, 201));
			}
			$page->metarobots= $this->input->post('metarobots');
			$page_link=$this->input->post('page_link')?$this->input->post('page_link'):$this->input->post('name');
			$page->page_link=url_title($page_link);
			//mis a jour date modification
			$page->date_create=strtotime('now');
			$this->model()->edit($page);
			global $CFG;
			$url=$CFG->config['base_url'].'page/admin';
			redirect($url);
		}
		public function create(){

			$this->load->helper('url');
			$page=new stdclass;
			
			$page->name= $this->input->post('name');
			$page->title= $this->input->post('title');
			
			$page->heading= $this->input->post('heading');
			$page->content= $this->input->post('content');
			$page->metakeywords= $this->input->post('metakeywords');
			$page->metadescription= $this->input->post('metadescription');
			if($page->metadescription==''){
				$page->metadescription=preg_replace('/\s+?(\S+)?$/', '', substr(strip_tags($page->content), 0, 201));
			}
			$page->metarobots= $this->input->post('metarobots');
			$page_link=$this->input->post('page_link')?$this->input->post('page_link'):$this->input->post('name');
			$page->page_link=url_title($page_link);
			//to do remplacer date de creation
			$page->date_create=strtotime('now');
			$this->model()->create($page);
			global $CFG;
			$url=$CFG->config['base_url'].'page/admin';
			redirect($url);
		}
}